setTimeout(function () {
    change_group(0);
    allList();
    payment();
    pending();
    receiving();
    estimate();
}, 100)
var url = "http://hengzhi.ayvvv.com";
var serCmsData = localStorage.getItem('token');
if (serCmsData == null) {
    window.location.href = "login.html";
}

function allList() {
    $.ajax({
        url: url + '/api/order/list?status=-2',
        dataType: 'json',
        type: 'get',
        async: true,
        headers: {
            "x-token": serCmsData
        },
        success: function (data) {
            if (data.status == 200) {
                var pagination = data.data.count;
                layui.use('laypage', function () {
                    var laypage = layui.laypage
                    laypage.render({
                        elem: 'box',
                        count: pagination,
                        jump: function (obj) {
                            console.log(obj.curr); //得到每页显示的条数
                            var page = obj.curr;
                            $.ajax({
                                url: url + '/api/order/list?status=-2',
                                dataType: 'json',
                                type: 'get',
                                async: true,
                                data: {
                                    page: page
                                },
                                headers: {
                                    "x-token": serCmsData
                                },
                                success: function (data) {
                                    console.log(data, "9999999999999999")
                                    if (data.status == 200) {
                                        $('.allList').empty();
                                        var Arr = data.data.list;
                                        for (var a = 0; a < Arr.length; a++) {
                                            for (var i = 0; i < Arr[a].orderProduct.length; i++) {
                                                // alert(Arr[a].order_sn)
                                                $('.allList').append(`
                                                <tr>
                                                <td>
                                                <a href="">` + Arr[a].order_sn + `</a>
                                                </td>
                                                <td>
                                                <a href=""><img src="` + Arr[a].orderProduct[i].cart_info.product.image + `" alt=""></a>
                                                </td>
                                                <td>` + Arr[a].real_name + `</td>
                                                <td>` + Arr[a].total_price + `</td>
                                                <td>` + Arr[a].create_time + `</td>
                                                <td> ` + Arr[a].status + `</td>
                                                <td>
                                                <a      id="toDetial" href="./detial.html?orderDetail=` + JSON.stringify(Arr[a].order_id) + `">查看</a> </td>
                                                </tr>`);
                                            }
                                        }


                                    }

                                }
                            })

                        }
                    });
                })
            } else {
                window.location.href = "login.html"
            }
        }
    });
}


function payment() {
    $.ajax({
        url: url + '/api/order/group_order_list',
        dataType: 'json',
        type: 'get',
        async: true,
        headers: {
            "x-token": serCmsData
        },
        success: function (data) {
            if (data.status == 200) {
                var pagination = data.data.count;
                console.log(pagination)
                layui.use('laypage', function () {
                    var laypage = layui.laypage
                    laypage.render({
                        elem: 'box1',
                        count: pagination,
                        jump: function (obj) {
                            $('.noPayment').empty();
                            console.log(obj.curr); //得到每页显示的条数
                            var page = obj.curr;
                            $.ajax({
                                url: url + '/api/order/group_order_list',
                                dataType: 'json',
                                type: 'get',
                                data: {
                                    page: page
                                },
                                async: true,
                                headers: {
                                    "x-token": serCmsData
                                },
                                success: function (data) {

                                    if (data.status == 200) {

                                        var Arr = data.data.list;
                                        for (var a = 0; a < Arr.length; a++) {
                                            for (var i = 0; i < Arr[a].orderList.length; i++) {
                                                for (var j = 0; j < Arr[a].orderList[i].orderProduct.length; j++) {
                                                    $('.noPayment').append(`
                                               <tr>
                                                <td>
                                                    <a href="">` + Arr[a].group_order_sn + `</a>
                                                </td>
                                                 <td>
                                                    <img src="` + Arr[a].orderList[i].orderProduct[j].cart_info.product.image + `">
                                                 </td>
                                                 <td>` + Arr[a].real_name + `</td>
                                                <td>` + Arr[a].total_price + `</td>
                                                 <td>` + Arr[a].create_time + `</td>
                                                
                                                 <td> 待付款 </td>
                                                <td><a href="./paymoney.html?nop=` + JSON.stringify(Arr[a].group_order_id) + `">查看</a> </td>
                                                </tr>
                                                 `);
                                                }
                                            }
                                            // <td> ` + Arr[a].orderList[i].orderProduct[j].cart_info.product.status + ` </td>
                                        }
                                    }
                                }

                            })
                        }
                    })
                })

            }

        }

    })
}


function pending() {
    $.ajax({
        url: url + '/api/order/list',
        dataType: 'json',
        type: 'get',
        data: {
            status: 0,
        },
        async: true,
        headers: {
            "x-token": serCmsData
        },
        success: function (data) {
            var pagination = data.data.count;
            layui.use('laypage', function () {
                var laypage = layui.laypage
                laypage.render({
                    elem: 'box2',
                    count: pagination,
                    jump: function (obj) {
                        console.log(obj.curr); //得到每页显示的条数
                        var page = obj.curr;
                        $.ajax({
                            url: url + '/api/order/list',
                            dataType: 'json',
                            type: 'get',
                            async: true,
                            data: {
                                status: 0,
                                page: page
                            },
                            headers: {
                                "x-token": serCmsData
                            },
                            success: function (data) {
                                if (data.status == 200) {
                                    $('.pending').empty();
                                    var Arr = data.data.list;
                                    for (var a = 0; a < Arr.length; a++) {
                                        for (var i = 0; i < Arr[a].orderProduct.length; i++) {
                                            $('.pending').append(`
                                           <tr>
                                            <td>
                                                <a href="">` + Arr[a].order_sn + `</a>
                                            </td>
                                             <td>
                                                <img src="` + Arr[a].orderProduct[i].cart_info.product.image + `">
                                             </td>
                                             <td>` + Arr[a].real_name + `</td>
                                            <td>` + Arr[a].total_price + `</td>
                                             <td>` + Arr[a].create_time + `</td>
                                            
                                             <td> 待发货</td>
                                            
                                            <td><a href="./paymoney.html?noop=` + Arr[a].order_id + `">查看</a> </td>
                                            </tr>
                                             `);
                                        }
                                    }
                                    // <td>` + Arr[a].status + ` </td>
                                }
                            }
                        })

                    }
                });
            })


        }
    });
}


function receiving() {
    $.ajax({
        url: url + '/api/order/list?status=0',
        dataType: 'json',
        type: 'get',
        data: {
            status: 1,
        },
        async: true,
        headers: {
            "x-token": serCmsData
        },
        success: function (data) {
            if (data.status == 200) {
                var pagination = data.data.count;
                layui.use('laypage', function () {
                    var laypage = layui.laypage
                    laypage.render({
                        elem: 'box3',
                        count: pagination,
                        jump: function (obj) {
                            console.log(obj.curr); //得到每页显示的条数
                            var page = obj.curr;
                            $.ajax({
                                url: url + '/api/order/list?status=0',
                                dataType: 'json',
                                type: 'get',
                                async: true,
                                data: {
                                    page: page,
                                    status: 1,
                                },
                                headers: {
                                    "x-token": serCmsData
                                },
                                success: function (data) {
                                    if (data.status == 200) {
                                        var Arr = data.data.list;
                                        for (var a = 0; a < Arr.length; a++) {
                                            for (var i = 0; i < Arr[a].orderProduct.length; i++) {
                                                $('.noReceiving').append(`
                                               <tr>
                                                <td>
                                                    <a href="">` + Arr[a].order_sn + `</a>
                                                </td>
                                                 <td>
                                                 <a href=""><img src="` + Arr[a].orderProduct[i].cart_info.product.image + `" alt=""></a>
                                                 </td>
                                                 <td>` + Arr[a].real_name + `</td>
                                                <td>` + Arr[a].total_price + `</td>
                                                 <td>` + Arr[a].create_time + `</td>
                                                 <td>待确认</td>
                                                <td><a href="./detial.html?orderDetail=` + JSON.stringify(Arr[a].order_id) + `">查看</a> </td>
                                             </tr>
                                                 `);
                                            }
                                        }
                                        // <td>` + data.data.count + ` </td>
                                    }
                                }
                            })

                        }
                    });
                })
            }



        }
    });
}


function estimate() {
    $.ajax({
        url: url + '/api/order/list?status=2',
        dataType: 'json',
        type: 'get',
        data: {
            status: 2,
        },
        async: true,
        headers: {
            "x-token": serCmsData
        },
        success: function (data) {
            if (data.status == 200) {
                var pagination = data.data.count;
                layui.use('laypage', function () {
                    var laypage = layui.laypage
                    laypage.render({
                        elem: 'box4',
                        count: pagination,
                        jump: function (obj) {
                            console.log(obj.curr); //得到每页显示的条数
                            var page = obj.curr;
                            $.ajax({
                                url: url + '/api/order/list?status=2',
                                dataType: 'json',
                                type: 'get',
                                async: true,
                                data: {
                                    page: page,
                                    status: 2,
                                },
                                headers: {
                                    "x-token": serCmsData
                                },
                                success: function (data) {

                                    if (data.status == 200) {
                                        var Arr = data.data.list;
                                        console.log(Arr, "1234567")
                                        for (var a = 0; a < Arr.length; a++) {
                                            for (var i = 0; i < Arr[a].orderProduct.length; i++) {
                                                $('.evaluate').append(`
                                               <tr>
                                                <td>
                                                    <a href="">` + Arr[a].order_sn + `</a>
                                                </td>
                                                 <td>
                                                 <a href=""><img src="` + Arr[a].orderProduct[i].cart_info.product.image + `" alt=""></a>
                                                 </td>
                                                 <td>` + Arr[a].real_name + `</td>
                                                <td>` + Arr[a].total_price + `</td>
                                                 <td>` + Arr[a].create_time + `</td>
                                                 <td>待评价</td>
                                                <td><a     href="./appraise.html?orderDetail=` + JSON.stringify(Arr[a].order_id) + '&ggg=' + JSON.stringify(Arr[a].orderProduct[0].order_product_id) + `  ">查看</a> </td>
                                             </tr>
                                                 `);
                                                //  var sss = Arr[a].orderProduct[0].order_product_id
                                                //  console.log(sss)

                                            }
                                        }
                                        // <td>` + data.data.count + ` </td>
                                    }
                                }
                            })

                        }
                    });
                })
            }



        }
    });
}
